package com.digitalart.nav {
	import flash.events.EventDispatcher;
	
	import com.digitalart.commons.CustomEvent;
	import com.digitalart.commons.CustomXmlLoader;
	
	import flash.events.Event;
	
	
	
	/**
	 * @author ulises.ocana
	 */     
	
	public class NavModel extends EventDispatcher{
		
		public static const PATH : String = "xml/nav.xml";
		public static const ON_ITEMS_CREATED : String = "onItemsCreated";
		
		private var _navItems : Array;
		private var _logoContainerText : String;
		private var _backGroundPath : String;
		private var _logoPath : String;
		
		private var _data : XML;
		
		/**********************************Constructor*************************/
		
		public function NavModel(){
			
			super(this);
			navItems = new Array();
			var loader : CustomXmlLoader = CustomXmlLoader.getInstance();
			loader.addEventListener(CustomXmlLoader.XML_LOAD_COMPLETE, dataLoaded);
			loader.loadXml(PATH);
		}
		
		/**********************************************************************/
		
		/**********************************Methods*************************/
		
		private function dataLoaded(e:CustomEvent) : void {
			
			e.target.removeEventListener(CustomXmlLoader.XML_LOAD_COMPLETE, dataLoaded);
			data = e.data;
			buildNavItems();
		}                                       
		
		private function buildNavItems() : void {       
			
			backGroundPath = data.assets.background.@src;
			logoPath = data.assets.logo.@src;
			logoContainerText = data.logoContainerText;                     
			var navItemVO : NavItemVO;
			for each(var navItem : XML in data.navMenuItems.item) {                                                 
				navItemVO = new NavItemVO(navItem.@id, navItem, navItem.@classAlias);
				navItems.push(navItemVO);
			}
			dispatchEvent(new Event(ON_ITEMS_CREATED));
		}
		
		public function get navItems() : Array{
			return _navItems;               
		}
		
		public function set navItems(navItems : Array) : void {
			_navItems = navItems;
		}
		public function get data():XML{
			return _data;   
		}
		public function set data(data : XML):void{
			_data = data;
		}
		
		public function get backGroundPath() : String {
			return _backGroundPath;
		}
		
		public function set backGroundPath(backGroundPath : String) : void {
			_backGroundPath = backGroundPath;
		}
		
		public function get logoPath() : String {
			return _logoPath;
		}
		
		public function set logoPath(logoPath : String) : void {
			_logoPath = logoPath;
		}
		
		public function get logoContainerText() : String {
			return _logoContainerText;
		}
		
		public function set logoContainerText(logoContainerText : String) : void {
			_logoContainerText = logoContainerText;
		}
	}
}       
